package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.util.Result;
import com.h3c.nem.dto.TbApprovalRecordDTO;
import com.h3c.nem.dto.form.ConfigTheFormSubmit;
import com.h3c.nem.entity.TbApprovalRecord;
import com.h3c.nem.service.ITbApprovalRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Copyright (C), 2020-2020, h3c
 * FileName: TbApprovalRecordController
 *
 * @Author: l22886
 * @Date: 2022-01-19
 * Description: tb_approval_record controller
 * Version: 1.0
 */
@Api(tags = " TbApprovalRecord 接口")
@Slf4j
@RestController
@CrossOrigin
@RequestMapping(value = "/tbApprovalRecord", produces = "application/json;charset=utf-8")
public class TbApprovalRecordController {

    @Resource
    private ITbApprovalRecordService tbApprovalRecordService;

    /**
     * 查询新员工产生的审批记录
     *
     * @return
     */
    @GetMapping("/queryNewStaffRecord")
    public Result queryNewStaffRecord() {
        try {
            return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, tbApprovalRecordService.queryNewStaffRecord());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, 400, e.getMessage());
        }
    }

    /**
     * 查询新员工产生的未读审批角标
     *
     * @return
     */
    @GetMapping("/countNewStaffNoRead")
    public Result countNewStaffNoRead() {
        try {
            return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, tbApprovalRecordService.countNewStaffNoRead());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, 400, e.getMessage());
        }
    }

    @ApiOperation(value = "查询审批记录", notes = "查询审批记录")
    @ApiImplicitParam(name = "flowId", value = "工单编号", required = true)
    @PostMapping("/queryApprovalRecord")
    public Result queryApprovalRecord(@RequestBody TbApprovalRecordDTO dto) {
        Map<String, Object> retMap = tbApprovalRecordService.queryApprovalRecord(dto);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, retMap);
    }

    @ApiOperation(value = "月度考核/转正考核评价 草稿内容")
    @PostMapping("/queryApprovalDraft")
    public Result queryApprovalDraft(TbApprovalRecordDTO dto) {
        TbApprovalRecord approvalRecord = tbApprovalRecordService.queryApprovalDraft(dto);
        return new Result(true, StatusCodeEnum.SEARCH_SUCCESS, approvalRecord);
    }

    @ApiOperation(value = "审批")
    @PostMapping("/approve")
    public Result approve(@RequestBody TbApprovalRecordDTO dto) {
        Integer approve = tbApprovalRecordService.approve(dto);
        return new Result(true, StatusCodeEnum.NORMAL);
    }

    @ApiOperation(value = "移动审批审批操作接口")
    @PostMapping("/wxApproveWithFile")
    public Map<String, Object> wxApprove(@ModelAttribute ConfigTheFormSubmit formSubmit, MultipartHttpServletRequest request) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            tbApprovalRecordService.wxApprove(formSubmit);
            resultMap.put("success", true);
            resultMap.put("message", "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            resultMap.put("success", false);
            resultMap.put("message", "处理异常");
        }
        return resultMap;
    }
}